Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hapi/wreck

Package Overview
Dependencies
Maintainers
6
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hapi/wreck

HTTP Client Utilities

  • 17.2.0
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Maintainers
6
Created

What is @hapi/wreck?

@hapi/wreck is a powerful HTTP client library for Node.js, designed to make HTTP requests and handle responses with ease. It is part of the hapi ecosystem and provides a simple and consistent API for making HTTP requests, handling redirects, and managing cookies.

What are @hapi/wreck's main functionalities?

Making HTTP GET Requests

This feature allows you to make HTTP GET requests to a specified URL and handle the response. The example fetches data from a placeholder API and logs the response.

const Wreck = require('@hapi/wreck');

async function fetchData() {
  const { res, payload } = await Wreck.get('https://jsonplaceholder.typicode.com/posts/1');
  console.log(JSON.parse(payload.toString()));
}

fetchData();

Making HTTP POST Requests

This feature allows you to make HTTP POST requests with a payload. The example sends a JSON object to a placeholder API and logs the response.

const Wreck = require('@hapi/wreck');

async function postData() {
  const payload = JSON.stringify({ title: 'foo', body: 'bar', userId: 1 });
  const { res, payload: responsePayload } = await Wreck.post('https://jsonplaceholder.typicode.com/posts', { payload });
  console.log(JSON.parse(responsePayload.toString()));
}

postData();

Handling Redirects

This feature allows you to handle HTTP redirects automatically. The example makes a GET request to a URL and follows up to 3 redirects.

const Wreck = require('@hapi/wreck');

async function fetchWithRedirect() {
  const { res, payload } = await Wreck.get('http://example.com', { redirects: 3 });
  console.log(payload.toString());
}

fetchWithRedirect();

Managing Cookies

This feature allows you to manage cookies for your HTTP requests. The example sets a cookie and makes a GET request with the cookie jar.

const Wreck = require('@hapi/wreck');

async function fetchWithCookies() {
  const jar = new Wreck.CookieJar();
  await jar.setCookie('session=abc123', 'http://example.com');
  const { res, payload } = await Wreck.get('http://example.com', { cookies: jar });
  console.log(payload.toString());
}

fetchWithCookies();

Other packages similar to @hapi/wreck

Keywords

FAQs

Package last updated on 25 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc